package com.yangff.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yangff.anno.LogExecuteTime;
import com.yangff.entity.transaction.entity.Transactionrecord;
import com.yangff.entity.transaction.entity.dto.TransactionrecordDTO;
import com.yangff.entity.transaction.entity.vo.TransactionrecordVo;
import com.yangff.entity.vo.ResultVo;
import com.yangff.service.ITransactionrecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.security.NoSuchAlgorithmException;
import java.util.List;

/**
 * <p>
 * 存储用户的交易记录 前端控制器
 * </p>
 *
 * @author yangff
 * @since 2025-01-19
 */
@LogExecuteTime
@RestController
@RequiredArgsConstructor
@RequestMapping("/transactionrecord")
public class TransactionrecordController {
    private final ITransactionrecordService transactionrecordService;

    @GetMapping("/account")
    public List<TransactionrecordVo> getTransactionrecordByAccount(String account) {
        List<Transactionrecord> transactionrecords = transactionrecordService.list(new LambdaQueryWrapper<Transactionrecord>().eq(Transactionrecord::getAccount,account));
        return BeanUtil.copyToList(transactionrecords, TransactionrecordVo.class);
    }

    @PostMapping
    public ResultVo saveTransactionrecord(@RequestBody TransactionrecordDTO transactionrecordDTO) throws NoSuchAlgorithmException {
       return transactionrecordService.saveTransactionrocord(transactionrecordDTO);
    }

}
